package  com.hoas.api.core;

import static  com.hoas.api.core.encrypt.rsa.RSAEncrypt.encrypt;
import static  com.hoas.api.core.encrypt.rsa.RSAEncrypt.loadPublicKeyByStr;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;

import  com.hoas.api.core.encrypt.Base64;



@RunWith(SpringJUnit4ClassRunner.class)  
@SpringBootTest(classes=ApiStarter.class)// 指定spring-boot的启动类   
@WebAppConfiguration
@AutoConfigureMockMvc
public class ApiMockBase {
       
	@Autowired(required=true)
    private MockMvc mvc;
	
	private final String PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdXHtrqwK1clNRYqTTHIsoJxY0I0XBBxYsrgeOG4PF51p6BQ9Qi8CKg2PaBrz9qp5sqPsH1QBIDmINkOkpbAXzt//M9sBOT17cckSitCI6CNhEOhV4yLo0lBIcXml0iuGVJbqGnwHHaibtKk1j07cUQzWw0CgM2Gfj8mye2Q9kxwIDAQAB";
	

	public String callApiWithRSA(String token,String bussinessId, String params) throws Exception {
		String resp = mvc.perform(
			post("/api")
				.param("token", token)
				.param("businessId", bussinessId)
				.param("param", Base64.encode(encrypt(loadPublicKeyByStr(PUBLIC_KEY), paramStr.getBytes()))))
			.andReturn().getResponse().getContentAsString();
		return resp;
		
	}

	@Test
	public void callApi(){



	}
	
}  